import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_checking/checking/china_date.dart';

import 'data/data.dart';

///
/// @author: maker
/// @date: 2021/4/15 9:57
/// description: 考情签到使用控件
///
class CheckingWidget {
  /// 标题栏
  Widget buildCheckingAppBar(
      BuildContext context, Function onTapSignStatisticsExport) {
    return Container(
      height: 44.0,
      margin: EdgeInsets.only(
          top: MediaQuery.of(context).padding.top + 10.0,
          left: 14.0,
          right: 8.0),
      child: Stack(
        alignment: Alignment.center,
        children: [
          Text(
            "考勤签到",
            style: TextStyle(
                fontSize: 17.0,
                fontWeight: FontWeight.bold,
                color: Color(0xFF333333)),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: () => Navigator.of(context).pop(),
                child: Icon(
                  Icons.arrow_back_ios_rounded,
                  size: 18.0,
                  color: Color(0xFF1D1D1D),
                ),
              ),
              Visibility(
                visible: false,
                child: InkWell(
                  onTap: () => onTapSignStatisticsExport(),
                  child: Container(
                    height: 32.0,
                    alignment: Alignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(16.0),
                        gradient: LinearGradient(colors: [
                          Color(0xFF2BAEF8),
                          Color(0xFF1376EE),
                        ])),
                    child: Text(
                      "签到统计导出",
                      style: TextStyle(fontSize: 14.0, color: Colors.white),
                    ),
                  ),
                ),
              )
            ],
          )
        ],
      ),
    );
  }

  /// 考勤签到底部按钮
  Widget buildCheckingBottomButton(
      int currentIndex, Function onTapButtonButton) {
    return Align(
      alignment: Alignment.bottomCenter,
      child: Container(
        height: 54.0,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            border:
                Border(top: BorderSide(width: 1.0, color: Color(0xFFEDEDED)))),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            buildCheckingBottomButtonItem(currentIndex, 0, onTapButtonButton),
            buildCheckingBottomButtonItem(currentIndex, 1, onTapButtonButton),
          ],
        ),
      ),
    );
  }

  /// 考勤签到底部单个按钮
  Widget buildCheckingBottomButtonItem(
      int currentIndex, int index, Function onTapButtonButton) {
    return Expanded(
        child: InkWell(
      onTap: () => onTapButtonButton(index),
      child: Container(
        alignment: Alignment.center,
        padding: EdgeInsets.only(top: 6.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            index == 0
                ? Image.asset(
                    currentIndex == index
                        ? "assets/images/sign_in_check.png"
                        : "assets/images/sign_in_uncheck.png",
                    width: 24.0,
                    height: 24.0,
                  )
                : Image.asset(
                    currentIndex == index
                        ? "assets/images/sign_statistic_check.png"
                        : "assets/images/sign_statistic_uncheck.png",
                    width: 24.0,
                    height: 24.0,
                  ),
            Text(
              index == 0 ? "签到" : "考勤统计",
              style: TextStyle(
                  fontSize: 12.0,
                  color: currentIndex == index
                      ? Color(0xFF1376EE)
                      : Color(0xFF999999)),
            )
          ],
        ),
      ),
    ));
  }

  /// 签到页
  Widget buildSignContainer(
      BuildContext context, Widget signLocation, Widget signButton) {
    return Container(
      margin: EdgeInsets.only(
          top: MediaQuery.of(context).padding.top + 10.0 + 44.0 + 8.0,
          bottom: 54.0 + 8.0,
          left: 8.0,
          right: 8.0),
      child: ListView(
        padding: EdgeInsets.all(0.0),
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(8.0),
            child: Image.asset(
              "assets/images/sign_header.jpg",
              height: 190.0,
              fit: BoxFit.fitWidth,
            ),
          ),
          SizedBox(
            height: 32.0,
          ),
          signLocation,
          SizedBox(
            height: 32.0,
          ),
          signButton,
        ],
      ),
    );
  }

  Widget buildSignLocation(String address, Widget refreshButton) {
    return Container(
      alignment: Alignment.center,
      child: Row(
        children: [
          SizedBox(
            width: 40.0,
          ),
          Expanded(
              child: Text(
            address,
            style: TextStyle(
                fontSize: 17.0,
                color: Color(0xFF333333),
                fontWeight: FontWeight.bold),
          )),
          SizedBox(
            width: 12.0,
          ),
          refreshButton,
          SizedBox(
            width: 16.0,
          ),
        ],
      ),
    );
  }

  Widget buildSignRefreshButton(Function onTapRefreshLocation) {
    return InkWell(
      onTap: () => onTapRefreshLocation(),
      child: Container(
        padding: EdgeInsets.all(6.0),
        child: Image.asset(
          "assets/images/location_refresh.png",
          width: 16.0,
          height: 16.0,
        ),
      ),
    );
  }

  Widget buildSignButton(
      int hour,
      String time, int type, Widget radar, Function onTapSign) {
    hour >= 9 ? type = 2 :type = 1;
    return Container(
      alignment: Alignment.center,
      child: Column(
        children: [
          GestureDetector(
            onTap: () => onTapSign(),
            child: Stack(
              children: [
                Container(
                  height: 144.0,
                  width: 144.0,
                  alignment: Alignment.center,
                  padding: EdgeInsets.only(top: 40.0),
                  decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      gradient: LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: type == 1
                              ? [
                                  Color(0xFF1DE0FA),
                                  Color(0xFF1376EE),
                                ]
                              : [
                                  Color(0xFFFFB164),
                                  Color(0xFFED6230),
                                ]),
                      boxShadow: [
                        BoxShadow(
                            offset: Offset(0, 40.0),
                            color: type == 1
                                ? Color(0xFF1376EE)
                                : Color(0xFFED6230),
                            blurRadius: 36.0,
                            spreadRadius: -36.0),
                      ]),
                  child: Column(
                    children: [
                      Text(
                        "打卡",
                        style: TextStyle(
                          fontSize: 32.0,
                          color: Colors.white,
                        ),
                      ),
                      SizedBox(
                        height: 4.0,
                      ),
                      Text(
                        time,
                        style: TextStyle(fontSize: 24.0, color: Colors.white),
                      ),
                    ],
                  ),
                ),
                radar,
              ],
            ),
          ),
          SizedBox(
            height: 16.0,
          ),
          Visibility(
            visible: type == 2 || type == 3,
            child: Text(
              type == 2 ? "迟到签到" : "早退签到",
              style: TextStyle(fontSize: 14.0, color: Color(0xFF6666666)),
            ),
          ),
        ],
      ),
    );
  }

  String getCurrentTime(DateTime dateTime) {
    String hour = dateTime.hour > 9
        ? dateTime.hour.toString()
        : "0${dateTime.hour.toString()}";
    String min = dateTime.minute > 9
        ? dateTime.minute.toString()
        : "0${dateTime.minute.toString()}";
    String sec = dateTime.second > 9
        ? dateTime.second.toString()
        : "0${dateTime.second.toString()}";
    return "$hour:$min:$sec";
  }

  /// 雷达扫描
  Widget buildRadarSweep(AnimationController controller) {
    return RotationTransition(
      turns: controller,
      child: ClipOval(
        child: Container(
          width: 144.0,
          height: 144.0,
          decoration: BoxDecoration(
              gradient: SweepGradient(
            colors: [
              Colors.white.withOpacity(0.5),
              Colors.white.withOpacity(0.1),
            ],
          )),
        ),
      ),
    );
  }

  void showSignDialog(
      BuildContext context, String title, Function onTapSignConfirm) {
    showDialog(
        context: context,
        builder: (context) {
          return Center(
            child: ClipRRect(
              borderRadius: BorderRadius.circular(8.0),
              child: Container(
                color: Colors.white,
                width: MediaQuery.of(context).size.width * 0.8,
                child: Wrap(
                  children: [
                    Column(
                      children: [
                        Container(
                          padding: EdgeInsets.only(
                              left: 16.0, right: 16.0, top: 32.0, bottom: 24.0),
                          alignment: Alignment.center,
                          child: Text(title,
                              style: TextStyle(
                                  fontSize: 17.0,
                                  color: Color(0xFF333333),
                                  decoration: TextDecoration.none),
                              maxLines: 3,
                              overflow: TextOverflow.ellipsis,
                              textAlign: TextAlign.center),
                        ),
                        Container(
                          height: 1.0,
                          color: Color(0xFFE5E5E5),
                        ),
                        GestureDetector(
                          onTap: () => onTapSignConfirm(),
                          child: Container(
                            padding: EdgeInsets.all(16.0),
                            alignment: Alignment.center,
                            child: Text(
                              "确定",
                              style: TextStyle(
                                  fontSize: 17.0,
                                  color: Color(0xFF1376EE),
                                  decoration: TextDecoration.none),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          );
        });
  }

  String getSignDialogContent(int type) {
    String content = "";
    switch (type) {
      case 1:
        content = "正常考勤签到，新的一天，\n愿工作愉快！";
        break;
      case 2:
        content = "本次考勤迟到，请知悉";
        break;
      case 3:
        content = "本次考勤早退，请知悉。";
        break;
      case 4:
        content = "正常考勤签到，工作一天辛苦了！";
        break;
      case 5:
        content = "考勤签到成功。\n越努力越幸运！";
        break;
      default:
        break;
    }
    return content;
  }

  void showDatePickers(BuildContext context, DateTime dateTime) {
    showDatePicker(
      context: context, //上下文对象
      initialDate: dateTime, //初始化显示的日期
      firstDate: DateTime(2019),
      lastDate: DateTime(2121),
    );
  }

  Widget buildSignStatisticsContainer(
      BuildContext context, List<Widget> widgets) {
    return Container(
      color: Color(0xFFF7F7F7),
      height: double.infinity,
      margin: EdgeInsets.only(
          top: MediaQuery.of(context).padding.top + 10.0 + 44.0 + 8.0,
          bottom: 54.0),
      child: ListView(
        padding: EdgeInsets.all(0.0),
        physics: NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        children: widgets,
      ),
    );
  }

  Widget buildSignStatisticsHeader(
      String date, bool isSpread, Function onTapDateFilter) {
    return Container(
      height: 54.0,
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            margin: EdgeInsets.only(left: 8.0),
            child: Text(
              "我的考勤统计",
              style: TextStyle(
                  fontSize: 17.0,
                  color: Color(0xFF333333),
                  fontWeight: FontWeight.bold),
            ),
          ),
          Visibility(
            visible: false,
            child: InkWell(
              onTap: () => onTapDateFilter(),
              child: Container(
                height: 32.0,
                margin: EdgeInsets.only(right: 8.0),
                padding: EdgeInsets.only(left: 24.0, right: 8.0),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(4.0),
                    border: Border.all(width: 1.0, color: Color(0xFFE2E2E2))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 16.0),
                      child: Text(
                        date,
                        style: TextStyle(
                            fontSize: 14.0,
                            color: Color(0xFF1376EE),
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                    Icon(
                      isSpread
                          ? Icons.arrow_drop_up_rounded
                          : Icons.arrow_drop_down_rounded,
                      size: 32.0,
                      color: Color(0xFFD8D8D8),
                    )
                  ],
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget buildSignStatisticCalendar(Function onTapCalendar) {
    return InkWell(
      onTap: () => onTapCalendar(),
      child: Container(
        child: Text("this is calendar"),
      ),
    );
  }

  Widget buildSignStatisticOfOneDay() {
    return Container(
      padding: EdgeInsets.only(left: 8.0, right: 8.0, top: 8.0, bottom: 24.0),
      margin: EdgeInsets.only(right: 8.0, left: 8.0, bottom: 8.0),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8.0), color: Colors.white),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "签到记录",
            style: TextStyle(
                fontSize: 17.0,
                color: Color(0xFF333333),
                fontWeight: FontWeight.bold),
          ),
          buildSignStatisticOfOneDayItem("8:45:56","浙江省杭州市西湖区龙井路1号",false),
          buildSignStatisticOfOneDayItem("17:23:41","上海市浦东新区世纪大道1号",true),
        ],
      ),
    );
  }

  Widget buildSignStatisticOfOneDayItem(String time,String location,bool exception) {
    return Container(
      margin: EdgeInsets.only(top: 16.0),
      child: Row(
        children: [
          Container(
            height: 10.0,
            width: 10.0,
            decoration:
                BoxDecoration(color: exception ? Color(0xFFFF8B23):Color(0xFF1376EE), shape: BoxShape.circle),
          ),
          SizedBox(
            width: 8.0,
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Text(
                    time,
                    style: TextStyle(
                        fontSize: 16.0,
                        color: Color(0xFF333333),
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    width: 8.0,
                  ),
                  Visibility(
                    visible: exception,
                    child: Container(
                      alignment: Alignment.center,
                      padding:
                          EdgeInsets.symmetric(horizontal: 6.0, vertical: 1.0),
                      decoration: BoxDecoration(
                        color: Color(0xFFFF8B23),
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                      child: Text(
                        "早退",
                        style: TextStyle(fontSize: 13.0, color: Colors.white),
                      ),
                    ),
                  )
                ],
              ),
              Text(
                location,
                style: TextStyle(fontSize: 14.0, color: Color(0xFF666666)),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              )
            ],
          )
        ],
      ),
    );
  }

  /// 导出签到统计-开始时间和结束时间
  /// startTime               开始时间
  /// endTime                 结束时间
  /// initialItem             开始时间初始化被选中时间
  /// isStartTime             是否是开始时间，true：开始时间  false：结束时间
  /// onTapCancel             取消按钮点击事件
  /// onTapConfirm            确认按钮点击事件，并返回被选中的时间
  /// onStartTimeChange
  Widget showSignStatisticsExportPicker(
    BuildContext context,
    List<Time> startTime,
    List<Time> endTime,
    int initialItem,
    bool isStartTime,
    Function onTapCancel,
    Function onTapConfirm,
  ) {
    // 默认开始时间为当前所在月份的1号，最早开始时间为2020年6月1号。最大可选择时间跨度为1个月
    FixedExtentScrollController scrollController =
        FixedExtentScrollController(initialItem: initialItem);
    String onSelectedStartTime = "开始时间";
    String onSelectedEndTime = "结束时间";
    /// 开始时间默认当当前所在月的1日开始，结束时间则通计算好的第一线开始
    int onSelectedValue = isStartTime ? initialItem : 0;
    return Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      color: Colors.black.withOpacity(0.6),
      alignment: Alignment.bottomCenter,
      child: Container(
          height: MediaQuery.of(context).size.height * 2 / 5,
          color: Colors.white,
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  InkWell(
                    onTap: () => onTapCancel(),
                    child: Container(
                        padding: EdgeInsets.only(
                            left: 24.0, right: 24.0, top: 16.0, bottom: 16.0),
                        child: Text("取消",
                            style: TextStyle(
                                fontSize: 14.0, color: Color(0xFF666666)))),
                  ),
                  Text(isStartTime ? onSelectedStartTime : onSelectedEndTime,
                      style: TextStyle(
                          fontSize: 14.0, color: Color(0xFF666666))),
                  InkWell(
                    onTap: () => onTapConfirm(onSelectedValue),
                    child: Container(
                      padding: EdgeInsets.only(
                          left: 24.0, right: 24.0, top: 16.0, bottom: 16.0),
                      child: Text(
                        "确认",
                        style:
                            TextStyle(fontSize: 14.0, color: Color(0xFF1376EE)),
                      ),
                    ),
                  ),
                ],
              ),
              Container(
                height: 1.0,
                color: Color(0xFFEDEDED),
              ),
              Expanded(
                child: Row(
                  children: [
                    isStartTime ? Expanded(
                      child: CupertinoPicker(
                        itemExtent: 28.0,
                        useMagnifier: true,
                        magnification: 1.5,
                        scrollController: scrollController,
                        onSelectedItemChanged: (value) {
                          print("onSelectedStartTime:${startTime[value].toString()}");
                          onSelectedValue = value;
                        },
                        children: startTime
                            .map((e) => Text(
                                  e.toString(),
                                  style: TextStyle(
                                      fontSize: 17.0, color: Color(0xFF333333)),
                                ))
                            .toList(),
                      ),
                    ):
                    Expanded(
                      child: CupertinoPicker(
                        itemExtent: 28.0,
                        useMagnifier: true,
                        magnification: 1.5,
                        onSelectedItemChanged: (value) {
                          print("onSelectedEndTime:${endTime[value].toString()}");
                          onSelectedValue = value;
                        },
                        children: endTime
                            .map((e) => Text(e.toString(),
                                style: TextStyle(
                                    fontSize: 16.0, color: Color(0xFF333333))))
                            .toList(),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          )),
    );
  }


  /// 计算签到统计开始时间
  List<Time> calculateStartTime(DateTime dateTime) {
    int year = dateTime.year;
    int month = dateTime.month;
    int day = dateTime.day;
    List<Time> startTime = [];
    // 添加2020开始时间
    startTime.addAll(timeOf2020);
    for (int y = 2021; y <= year; y++) {
      if (y < 2021) {
        for (int i = 1; i <= 12; i++) {
          int days = ChinaDateUtils.getDaysInMonth(y, i);
          for (int j = 1; j <= days; j++) {
            startTime.add(Time(y, i, j));
          }
        }
      } else {
        for (int i = 1; i < month; i++) {
          int days = ChinaDateUtils.getDaysInMonth(y, i);
          for (int j = 1; j <= days; j++) {
            startTime.add(Time(y, i, j));
          }
        }

        for (int m = 1; m <= day; m++) {
          startTime.add(Time(y, month, m));
        }
      }
    }
    print("endTime:${startTime.toString()}");
    return startTime;
  }

  /// 计算签到统计结束时间
  List<Time> calculateEndTime(Time time) {
    int year = time.year;
    int month = time.month;
    int day = time.day;
    List<Time> endTime = [];

    int days = ChinaDateUtils.getDaysInMonth(year, month);
    for (int j = day + 1; j < days; j++) {
      endTime.add(Time(year, month, j));
    }

    if (month + 1 > 12) {
      for (int j = 1; j <= day; j++) {
        endTime.add(Time(year + 1, month + 1 - 12, j));
      }
    } else {
      for (int j = 1; j <= day; j++) {
        endTime.add(Time(year, month + 1, j));
      }
    }

    print("endTime:${endTime.toString()}");

    return endTime;
  }

  /// 我的考勤统计顶部时间筛选，只包含年月
  Widget showSignStatisticsTopTimePicker(
      BuildContext context,
      List<YearAndMonthTime> months,
      Function onTapMonthCancel,
      Function onTapMonthConfirm,
      ValueChanged onMonthChanged) {
    FixedExtentScrollController scrollController =
        FixedExtentScrollController(initialItem: months.length - 1);

    List<Widget> children = months
        .map((e) => Text(e.toString(),
            style: TextStyle(fontSize: 16.0, color: Color(0xFF333333))))
        .toList();
    return Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      color: Colors.black.withOpacity(0.6),
      alignment: Alignment.bottomCenter,
      child: Container(
          height: MediaQuery.of(context).size.height * 2 / 5,
          color: Colors.white,
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  InkWell(
                    onTap: () => onTapMonthCancel(),
                    child: Container(
                        padding: EdgeInsets.only(
                            left: 16.0, right: 16.0, top: 8.0, bottom: 8.0),
                        child: Text("取消",
                            style: TextStyle(
                                fontSize: 16.0, color: Color(0xFF666666)))),
                  ),
                  InkWell(
                    onTap: () => onTapMonthConfirm(),
                    child: Container(
                      padding: EdgeInsets.only(
                          left: 16.0, right: 16.0, top: 8.0, bottom: 8.0),
                      child: Text(
                        "确认",
                        style:
                            TextStyle(fontSize: 16.0, color: Color(0xFF1376EE)),
                      ),
                    ),
                  ),
                ],
              ),
              Container(
                height: 1.0,
                color: Color(0xFFEDEDED),
              ),
              Expanded(
                child: Row(
                  children: [
                    Expanded(
                      child: CupertinoPicker(
                        itemExtent: 28.0,
                        useMagnifier: true,
                        magnification: 1.5,
                        scrollController: scrollController,
                        onSelectedItemChanged: (value) {
                          onMonthChanged(value);
                        },
                        children: children,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          )),
    );
  }

  // 添加我的考勤统计时间筛选，只包含年月
  List<YearAndMonthTime> calculateMonths(DateTime dateTime) {
    List<YearAndMonthTime> months = [];
    months.addAll(monthOf2020);
    int month = dateTime.month;
    int year = dateTime.year;

    for (int j = 2021; j <= year; j++) {
      if (j < year) {
        for (int m = 1; m <= 12; m++) {
          months.add(YearAndMonthTime(j, m));
        }
      } else {
        for (int m = 1; m <= month; m++) {
          months.add(YearAndMonthTime(j, m));
        }
      }
    }

    return months;
  }

  /// 导出签到统计底部筛选面板
  Widget showSignStatisticsBottomSheet(
    BuildContext context,
    String startTime,
    String endTime,
    String onSelectEmail,
    List<String> emails,
    TextEditingController textEditingController,
    Function onTapStartTime,
    Function onTapEndTime,
    Function onTapSignStatisticsCancel,
    Function onTapSignStatisticsConfirm,
    Function onTapEmailItem,
    ValueChanged onEmailChanged,
  ) {
    return Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      color: Colors.black.withOpacity(0.6),
      alignment: Alignment.bottomCenter,
      child: Container(
          height: MediaQuery.of(context).size.height * 2 / 5,
          color: Colors.white,
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  InkWell(
                    onTap: () => onTapSignStatisticsCancel(),
                    child: Container(
                        padding: EdgeInsets.only(
                            left: 24.0, right: 24.0, top: 16.0, bottom: 16.0),
                        child: Text("取消",
                            style: TextStyle(
                                fontSize: 14.0, color: Color(0xFF666666)))),
                  ),
                  Text("导出签到记录",
                      style:
                          TextStyle(fontSize: 14.0, color: Color(0xFF666666))),
                  InkWell(
                    onTap: () => onTapSignStatisticsConfirm(),
                    child: Container(
                      padding: EdgeInsets.only(
                          left: 24.0, right: 24.0, top: 16.0, bottom: 16.0),
                      child: Text(
                        "确认",
                        style:
                            TextStyle(fontSize: 14.0, color: Color(0xFF1376EE)),
                      ),
                    ),
                  ),
                ],
              ),
              Container(
                height: 1.0,
                color: Color(0xFFEDEDED),
              ),
              SizedBox(
                height: 8.0,
              ),
              Row(
                children: [
                  Expanded(
                      child: InkWell(
                    onTap: () => onTapStartTime(),
                    child: Container(
                      height: 32.0,
                      margin: EdgeInsets.only(right: 8.0, left: 24.0),
                      padding: EdgeInsets.only(left: 24.0, right: 8.0),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(4.0),
                          border:
                              Border.all(width: 1.0, color: Color(0xFFE2E2E2))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Container(
                            child: Text(
                              startTime,
                              style: TextStyle(
                                fontSize: 14.0,
                                color: startTime == "开始时间"
                                    ? Color(0xFF666666)
                                    : Color(0xFF1376EE),
                              ),
                            ),
                          ),
                          Icon(
                            Icons.arrow_drop_down_rounded,
                            size: 32.0,
                            color: Color(0xFFD8D8D8),
                          )
                        ],
                      ),
                    ),
                  )),
                  Expanded(
                      child: InkWell(
                    onTap: () => onTapEndTime(),
                    child: Container(
                      height: 32.0,
                      margin: EdgeInsets.only(right: 24.0, left: 8.0),
                      padding: EdgeInsets.only(left: 24.0, right: 8.0),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(4.0),
                          border:
                              Border.all(width: 1.0, color: Color(0xFFE2E2E2))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Container(
                            child: Text(
                              endTime,
                              style: TextStyle(
                                fontSize: 14.0,
                                color: endTime == "结束时间"
                                    ? Color(0xFF666666)
                                    : Color(0xFF1376EE),
                              ),
                            ),
                          ),
                          Icon(
                            Icons.arrow_drop_down_rounded,
                            size: 32.0,
                            color: Color(0xFFD8D8D8),
                          )
                        ],
                      ),
                    ),
                  )),
                ],
              ),
              SizedBox(
                height: 8.0,
              ),
              Container(
                height: 1.0,
                margin: EdgeInsets.only(left: 24.0),
                color: Color(0xFFE4E4E4),
              ),
              Container(
                  margin: EdgeInsets.only(left: 24.0),
                  child: TextField(
                    controller: textEditingController,
                    decoration: InputDecoration(
                      hintText: "请输入或选择接收邮箱地址",
                      hintStyle:
                          TextStyle(fontSize: 14.0, color: Color(0xFF666666)),
                    ),
                    style: TextStyle(
                        fontSize: 14.0,
                        color: Color(0xFF333333),
                        fontWeight: FontWeight.bold),
                    onChanged: (value) => onEmailChanged(value),
                    maxLines: 1,
                  )),
              Expanded(
                child: ListView(
                  children: emails
                      .map((e) => buildEmailItem(
                          e, onSelectEmail.isNotEmpty, onTapEmailItem))
                      .toList(),
                ),
              )
            ],
          )),
    );
  }

  Widget buildEmailItem(String email, bool input, Function onTapEmail) {
    return InkWell(
      onTap: () => onTapEmail(email),
      child: Container(
        alignment: Alignment.center,
        padding: EdgeInsets.all(8.0),
        decoration: BoxDecoration(
          color: input ? Colors.white : Color(0xFFDBEBFF),
          borderRadius: BorderRadius.circular(4.0),
        ),
        child: Text(
          email,
          style: TextStyle(
              fontSize: 14.0,
              color: input ? Color(0xFF333333) : Color(0xFF1376EE)),
        ),
      ),
    );
  }
}
